package handlers

import (
	"github.com/gin-gonic/gin"
	"strconv"
	"xiao-hong-shu-app/models"
)

func List(c *gin.Context) {
	page, _ := strconv.Atoi(c.Query("page"))
	size, _ := strconv.Atoi(c.Query("size"))
	offset := (page - 1) * size
	var count int64
	models.DB.Model(&models.Article{}).Count(&count)
	var article []models.Article

	err := models.DB.Offset(offset).Limit(size).Find(&article).Error
	if err != nil {
		c.JSON(200, gin.H{
			"code": 500,
			"msg":  "列表展示失败",
		})
		return
	}
	c.JSON(200, gin.H{
		"code":  200,
		"msg":   "列表展示成功",
		"data":  article,
		"count": count,
	})
	return

}
